<?php include './admin/view/header.inc.htm'; ?>

<div class="panel">
	<div class="header">编辑用户-<?=$user['username']?></div>
	<div class="body">
		<form method="POST" action="admin/user-update-<?=$uid?>.htm" id="form">
			<table class="form">
				<tr style="display: none;">
					<th>手机号：</th>
					<td><input type="text" name="mobile" value="<?=$user['mobile']?>" /></td>
				</tr>
				<tr>
					<th>Email：</th>
					<td><input type="text" name="email" value="<?=$user['email']?>" /></td>
				</tr>
				<tr>
					<th>用户名：</th>
					<td><input type="text" name="username" value="<?=$user['username']?>" /></td>
				</tr>
				<tr>
					<th>密码：</th>
					<td><input type="password" name="password" id="password" /></td>
				</tr>
				<tr>
					<th>用户组：</th>
					<td>
						<select name="gid">
						<?php foreach($grouplist as $groupid=>$group) { ?>
							<option value="<?=$groupid?>" <?php if($user['gid'] == $groupid){ echo 'selected';  } ?>><?=$group['name']?></option>
						<?php } ?>
						</select>
					</td>
				</tr>
				<tr>
					<th>创建 IP：</th>
					<td><?=$user['create_ip_fmt']?></td>
				</tr>
				<tr>
					<th>创建日期：</th>
					<td><?=$user['create_date_fmt']?></td>
				</tr>
				<tr>
					<th>最后登录 IP：</th>
					<td><?=long2ip($user['login_ip_fmt'])?></td>
				</tr>
				<tr>
					<th>最后登录时间：</th>
					<td><?=$user['login_date_fmt']?></td>
					<td>&nbsp;</td>
				</tr>
				<tr>
					<th>登录次数：</th>
					<td width="250"><?=$user['logins']?></td>
				</tr>
				<tr>
					<th>&nbsp;</th>
					<td colspan="2"><button type="submit" id="submit" loading-text="正在提交" class="blue big">确定</button></td>
				</tr>
			</table>
		</form>
	</div>
</div>


<?php include './admin/view/footer.inc.htm'; ?>

<script>
var jform = $("#form");
var jsubmit = $("#submit");
var jmobile = jform.find('input[name="mobile"]');
var jemail = jform.find('input[name="email"]');
var jusername = jform.find('input[name="username"]');
var jpassword = jform.find('input[name="password"]');

jform.on('submit', function(){
	var password_bak = jpassword.val();
	if(password_bak) jpassword.val($.md5(password_bak));
	var postdata = jform.serialize();
	jpassword.val(password_bak);

	jsubmit.button('loading');
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			jsubmit.text(message);
			setTimeout(function(){
				window.location = 'admin/user-list.htm';
			}, 2000);
			return false;
		} else if(code == 1) {
			jmobile.popover(message).focus();
		} else if(code == 2) {
			jemail.popover(message).focus();
		} else if(code == 3) {
			jusername.popover(message).focus();
		} else if(code == 4) {
			jpassword.popover(message).focus();
		} else {
			$.alert(message);
		}
		jsubmit.button('reset');
		
	});
	return false;
});
</script>